home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / patch / ps3ba1.lha / 3.0bupdate / Macros.LHA / OpenTemplate.rexx < prev    next >
OS/2 REXX Batch file  |  1994-09-22  |  8KB  |  263 lines

  1. /* $VER: OpenTemplate.rexx 1.0 (02.9.94)
  2.    Copyright 1994 Soft-Logik Publishing Corporation
  3.    May not be distributed without Soft-Logik Publishing Corporation's express written permission */
  4.  
  5. OPTIONS RESULTS
  6.  
  7. ADDRESS 'PAGESTREAM'
  8.  
  9. /* Make sure rexx support is opened */
  10. IF ~SHOW('L','rexxsupport.library') THEN
  11.    CALL ADDLIB('rexxsupport.library',0,-30)
  12.  
  13. /* Build the template list */
  14. dPath="PageStream3:Macros/TemplateData"
  15. Files=showdir(dPath,file,'|')
  16. fLength=length(Files)
  17.  
  18. /* Check for valid template data files. Only .data are listed */
  19. nList=0
  20. DO WHILE fLength>0
  21.     cLength=pos('|',Files)
  22.     IF cLength=0 then DO
  23.         cLength=FLength+1
  24.         fLength=0
  25.     END
  26.     cFile=left(Files,cLength-1)
  27.     eFile=right(cFile,cLength-lastpos('.',cFile))
  28.     IF eFile='.data' THEN DO
  29.         cFile=left(cFile,cLength-6)
  30.         nList=nList+1
  31.         List.nList=cFile
  32.     END
  33.     IF FLength~=0 THEN Files=right(Files,fLength-cLength)
  34.     fLength=fLength-cLength
  35. END
  36.  
  37. /* If there aren't any data files, alert the user and exit */
  38. IF nList=0 THEN DO
  39.     allocarexxrequester '"Open Template Alert"' 358 65
  40.         alerthandle=result
  41.     addarexxgadget alerthandle EXIT 276 48 70 label "_Exit"
  42.         cancelhandle=result
  43.     addarexxgadget alerthandle TEXT 8 8 346 string '"There are no template data files in the"'
  44.     addarexxgadget alerthandle TEXT 8 22 346 string '"PageStream3:Macros/TemplateData directory."'
  45.     doarexxrequester alerthandle
  46.         choice=result
  47.     freearexxrequester alerthandle
  48.     EXIT
  49. END
  50.  
  51. /* Sort the list alphabetically */
  52. DO tick = 1 to nList - 1
  53.     nexttick = tick + 1
  54.     IF List.tick > list.nexttick THEN
  55.         DO
  56.         store = List.nexttick
  57.         List.nexttick = List.tick
  58.  
  59.         DO bubpos = tick-1 to 1 by -1 WHILE (store < list.bubpos)
  60.             nexttick = bubpos + 1
  61.             List.nexttick = List.bubpos
  62.             END bubpos
  63.  
  64.         bubpos = bubpos + 1
  65.         List.bubpos = store
  66.         END
  67.     END tick
  68.  
  69. /* Allocate and fill the template list */
  70. allocarexxlist
  71.     tlisthandle=result
  72. i=1
  73. DO WHILE i<nList+1
  74.     addarexxlist tlisthandle List.i
  75.     i=i+1
  76. END
  77.  
  78. /* Allocate template list requester */
  79. allocarexxrequester '"Open Template"' 266 201
  80.     reqhandle=result
  81.  
  82. /* Add gadgets */
  83. addarexxgadget reqhandle EXIT 12 184 70 label "_Open"
  84.     openhandle=result
  85. addarexxgadget reqhandle EXIT 184 184 70 label "_Cancel"
  86.     cancelhandle=result
  87. addarexxgadget reqhandle SCROLLIST 12 8 242 label list tlisthandle current 0 height 166
  88.     templatehandle=result
  89.  
  90. /*********************************
  91. ** Show template list requester **
  92. *********************************/
  93.  
  94. doarexxrequester reqhandle
  95.     choice=result
  96.  
  97. /* Get list status */
  98. getarexxgadget reqhandle templatehandle current
  99. i=result+1
  100. tFile=dPath||'/'||List.i||'.data'
  101. docname='Untitled_'||List.i
  102.  
  103. /* set a flag so we know if it's avery labels */
  104. avery=0
  105. if List.i='AveryLabels' then avery=1
  106.  
  107. /* Unallocate requester and list */
  108. freearexxlist tlisthandle
  109. freearexxrequester reqhandle
  110.  
  111. /* If Cancel, then exit */
  112. if choice=cancelhandle then signal CLEANUP
  113.  
  114. /* Open the template data file */
  115. open(tfHandle, tFile, 'R')
  116.  
  117. /* Find out how many page sizes there are */
  118. line=readln(tfHandle)
  119.  
  120. parse var line numsizes .
  121.  
  122. /* Build a list of page sizes */
  123. allocarexxlist
  124.     slisthandle=result
  125. i=0
  126. DO WHILE i<numsizes
  127.     line=readln(tfHandle)
  128.     addarexxlist slisthandle line
  129.     i=i+1
  130. END
  131.  
  132. /*******************
  133. ** Page Size Loop **
  134. *******************/
  135. /* Why is this all in a loop? Because even though you can allocate a
  136.    requester, show a different one, then show the first one again, the size
  137.    of the first one changes to the size of the second one. Thus, it's best
  138.    to unallocate the requester after use and then re-allocate it. */
  139. choice=morehandle
  140. DO WHILE choice=morehandle
  141.  
  142.     /* Allocate page size list requester */
  143.     if avery=0 then DO
  144.         allocarexxrequester '"Choose a page size"' 266 201
  145.             sizereqhandle=result
  146.         END
  147.     else DO
  148.         allocarexxrequester '"Choose an Avery® label style"' 266 201
  149.             sizereqhandle=result
  150.     END
  151.  
  152.     /* Add gadgets */
  153.     addarexxgadget sizereqhandle EXIT 12 184 70 label "_Ok"
  154.         okhandle=result
  155.     addarexxgadget sizereqhandle EXIT 184 184 70 label "_Cancel"
  156.         cancelhandle=result
  157.     if avery=1 then DO
  158.         addarexxgadget sizereqhandle EXIT 98 184 70 label "_More"
  159.             morehandle=result
  160.     END
  161.     addarexxgadget sizereqhandle SCROLLIST 12 8 242 label list slisthandle current 0 height 166
  162.         pagesizehandle=result
  163.  
  164.     /**********************************
  165.     ** Show page size list requester **
  166.     **********************************/
  167.     doarexxrequester sizereqhandle
  168.         choice=result
  169.  
  170.     /* Get list status */
  171.     getarexxgadget sizereqhandle pagesizehandle current
  172.     skipahead=result
  173.  
  174.     /* Unallocate requester */
  175.     freearexxrequester sizereqhandle
  176.  
  177.     if choice=morehandle then DO
  178.         allocarexxrequester '"Other label sizes"' 400 101
  179.             morereqhandle=result
  180.         addarexxgadget morereqhandle EXIT 318 84 70 label "_Ok"
  181.         addarexxgadget morereqhandle TEXT 8 8 384 border none string "'If you need a label size which is not listed'"
  182.         addarexxgadget morereqhandle TEXT 8 18 384 border none string "'here, send one sheet of the label to us and'"
  183.         addarexxgadget morereqhandle TEXT 8 28 384 border none string "'we will update this macro for you. Send to:'"
  184.         addarexxgadget morereqhandle TEXT 8 44 384 border none string "'Soft-Logik Publishing: Product Development'"
  185.         addarexxgadget morereqhandle TEXT 8 54 384 border none string "'11131F South Towne Square'"
  186.         addarexxgadget morereqhandle TEXT 8 64 384 border none string "'St. Louis, MO  63123  USA'"
  187.         doarexxrequester morereqhandle
  188.     END
  189. END
  190.  
  191. /* Unallocate list */
  192. freearexxlist slisthandle
  193.  
  194. /* If Cancel, then exit */
  195. if choice=cancelhandle then signal CLEANUP
  196.  
  197. /* Skip extra page size lines in data file */
  198. i=0
  199. DO WHILE i<skipahead
  200.     line=readln(tfHandle)
  201.     i=i+1
  202. END
  203.  
  204. /* Get the page size info */
  205. line=readln(tfHandle)
  206. parse var line dum horz vert orient face margin.l margin.r margin.t margin.b columns gutter msys guides inc .
  207.  
  208. /* Skip extra page size lines in data file */
  209. i=0
  210. DO WHILE i<(numsizes-skipahead-1)
  211.     readln(tfHandle)
  212.     i=i+1
  213. END
  214.  
  215. /* build the list of guides to create */
  216. i=0
  217. tempos=margin.t
  218. horzguides=""
  219. vertguides=""
  220. DO WHILE i<guides
  221.     tempos=tempos+inc
  222.     horzguides=horzguides||' '||tempos
  223.     i=i+1
  224. END
  225. /* now add custom guide positions to the list */
  226. hpos=pos('*h',line)
  227. vpos=pos('*v',line)
  228. horzguides=horzguides||substr(line,(hpos+2),(vpos-hpos-3))
  229. vertguides=vertguides||right(line,(length(line)-vpos-1))
  230.  
  231. /************************
  232. ** Create the document **
  233. ************************/
  234. trace ?i
  235. 'newdocument '||docname
  236. 'newmasterpage "Default Master Page" '||horz vert orient face
  237. 'setmeasurementdefaults coordinate '||msys mysys||' relative '||msys
  238. 'setmarginguides '||margin.l margin.r margin.t margin.b
  239. 'setcolumnguides '||columns gutter
  240. if horzguides~="" then 'setguides mpg right horizontal at'||horzguides
  241. if vertguides~="" then 'setguides mpg right vertical at'||vertguides
  242.  
  243. /************************
  244. ** Open the window     **
  245. ************************/
  246. 'openwindow View.1 page 1'
  247. 'displayguides ruler page show'
  248. 'displaygrid hide'
  249. 'snaptogrid off'
  250. 'snaptoguides on'
  251. 'setdocumentstatus unchanged'
  252.  
  253. signal cleanup
  254.  
  255.  
  256.  
  257. /**********************
  258. ** Clean up and exit **
  259. **********************/
  260. CLEANUP:
  261. exit
  262. return 0
  263.